/*
 * @Author: 梁青春
 * @Date: 2022-04-22 11:41:34
 * @LastEditTime: 2022-04-24 11:25:37
 * @LastEditors: 梁青春
 */
import VueCookies from 'vue-cookies'
import router from '@/router'
import store from '@/store'

/**
 * 获取uuid
 */
export function getUUID () {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
    return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
  })
}

/**
 * 是否有权限
 * @param {*} key
 */
export function isAuth (key) {
  return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false
}

/**
 * 清除登录信息
 */
 export function clearLoginInfo () {
    VueCookies.delete('token')
    store.commit('resetStore')
    router.options.isAddDynamicMenuRoutes = false
  }
  /**
   * 获取基本色色阶
   * @param {*} color1 
   * @param {*} color2 
   * @param {*} weight 
   * @returns 
   */
   export function colorMix (color1, color2, weight) {
    weight = Math.max(Math.min(Number(weight), 1), 0)
    let r1 = parseInt(color1.substring(1, 3), 16)
    let g1 = parseInt(color1.substring(3, 5), 16)
    let b1 = parseInt(color1.substring(5, 7), 16)
    let r2 = parseInt(color2.substring(1, 3), 16)
    let g2 = parseInt(color2.substring(3, 5), 16)
    let b2 = parseInt(color2.substring(5, 7), 16)
    let r = Math.round(r1 * (1 - weight) + r2 * weight)
    let g = Math.round(g1 * (1 - weight) + g2 * weight)
    let b = Math.round(b1 * (1 - weight) + b2 * weight)
    r = ("0" + (r || 0).toString(16)).slice(-2)
    g = ("0" + (g || 0).toString(16)).slice(-2)
    b = ("0" + (b || 0).toString(16)).slice(-2)
    return "#" + r + g + b;
  }